package game;



import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;


public class WaveGames extends GameObject implements Runnable, ActionListener
{

	private static final long serialVersionUID = 1L;

	Point2D centerPosition;
	Point2D sizeMax;
	Point2D sizeMin;
	Point2D velocity;
	boolean figuraCrescendo = false;
	
	boolean abriuSite = false;
	
	public WaveGames(int index, Point2D position, Point2D size) {
		super(index, position, size);
		// TODO Auto-generated constructor stub
		this.sizeMax = size;
		this.sizeMin = new Point2D.Double(0, 0);
		this.centerPosition = new Point2D.Double(750, 550);
		
		velocity = new Point2D.Double((this.sizeMax.getX() - this.sizeMin.getX())/100, 
				(this.sizeMax.getY() - this.sizeMin.getY())/100);
	}

	public void update()
	{
		if(this.getRectangle().contains(Mouse.getInstance().getPositionMouse()) && Mouse.getInstance().isMousePressed(MouseEvent.BUTTON1))
		{
			if(this.abriuSite == false)
			{
				Audios.getInstance().Play(4);
				Game.AbrirURL();
				this.abriuSite = true;
			}
		}
		else if(Mouse.getInstance().isMousePressed(MouseEvent.BUTTON1) == false)
		{
			this.abriuSite = false;
		}
		
		
		if(figuraCrescendo)
		{
			this.setDimension(new Point2D.Double(this.dimension.getX() + velocity.getX(), this.dimension.getY()  + velocity.getY()));
			if(this.getDimension().getX() >= this.sizeMax.getX())
			{
				this.setDimension(this.sizeMax);
				this.figuraCrescendo = false;
			}
		}
		else
		{
			this.setDimension(new Point2D.Double(this.dimension.getX() - velocity.getX(), this.dimension.getY()  - velocity.getY()));
			if(this.getDimension().getX() <= this.sizeMin.getX())
			{
				this.setDimension(this.sizeMin);
				this.figuraCrescendo = true;
			}
		}
		
		this.setPosition( new Point2D.Double(	this.centerPosition.getX() - (this.getDimension().getX()/2),
												this.centerPosition.getY() - (this.getDimension().getY()/2)));
	
		super.update();
		
	}
	
	public void draw(Graphics g)
	{
		g.drawImage(this.getImage(), (int)this.getPosition().getX(), (int)this.getPosition().getY(), (int)this.getDimension().getX(), (int)this.getDimension().getY(), null);
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}
}
